<?php $this->layout = "//layouts/column1"; ?>
<?php
/* @var $this SiteController */

$this->pageTitle = Yii::app()->name . ' - FAQ';
$this->breadcrumbs = array(
    'FAQ',
);
?>
<h1>Youtubetester(only for admin)</h1>
<a href="javascript:void(0);" onclick="play();">Play</a>
<!--<div style="font-size: 15px">
    <iframe onload="onYouTubePlayerReady('myytplayer')" id="ytplayer" type="text/html" width="640" height="360"
            src="https://www.youtube.com/v/VBkmO1SQti4?enablejsapi=1&version=3&playerapiid=myytplayer"            
            frameborder="0" ></iframe>
</div>

 <script type="text/javascript">
    var params = { allowScriptAccess: "always" };
    function onYouTubePlayerReady(playerId) {
      ytplayer = document.getElementById("ytplayer");
      console.log(ytplayer);
    }

  </script>-->




















<div id="player"></div>

<script>
    var tag = document.createElement('script');

    tag.src = "https://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

    var player;
    function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
            height: '390',
            width: '640',
            videoId: 'nf8VlEqEO2Y',
            events: {
                'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange
            }
        });
    }

    function onPlayerReady(event) {
        //event.target.playVideo();
    }

    var timeCounterInterval;
    var timer=0;
    function onPlayerStateChange(event) {
        console.log(event.data);
        if(event.data == '1'){
            timeCounterInterval = setInterval(function(){startTimeCounting()},1000);
        }else{
            stopTimeCounting();
        }
    }
    
    
    function startTimeCounting()
    {
        timer++;
        console.log(timer);
        // here code for checking time and go server for transaction
    }

    function stopTimeCounting()
    {
        clearInterval(timeCounterInterval);
    }
</script>